package com.yami.shop.webservice.common.service.impl;

import cn.hutool.core.util.IdUtil;
import com.yami.shop.common.bean.PageDTO;
import com.yami.shop.common.bean.PageVO;
import com.yami.shop.common.util.PageUtil;
import com.yami.shop.webservice.common.dao.SubmittedClassMapper;
import com.yami.shop.webservice.common.model.ClassVo;
import com.yami.shop.webservice.common.service.WapiSubmittedClassService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class WapiSubmittedClassServiceImpl implements WapiSubmittedClassService {
    private final Logger log = LoggerFactory.getLogger(this.getClass());

    @Autowired
    private SubmittedClassMapper submittedClassMapper;

    @Override
    public ClassVo selectClassVoById(String id) {
        return submittedClassMapper.selectClassVoById(id);
    }

    @Override
    public List<ClassVo> selectClassVoList(ClassVo classVo) {
        return submittedClassMapper.selectClassVoList(classVo);
    }

    @Override
    public int insertClassVo(ClassVo classVo) {
        classVo.setId(IdUtil.getSnowflake().nextIdStr());
        classVo.setCreateTime(new Date());
        classVo.setStatus(0);
        return submittedClassMapper.insertClassVo(classVo);
    }

    @Override
    public int deleteClassVoById(String id) {
        return submittedClassMapper.deleteClassVoById(id);
    }

	@Override
	public Boolean selectClassVoByProductCode(String productCode) {
		ClassVo classVo = new ClassVo();
		classVo.setStatus(1);
		classVo.setProductCode(productCode);
		 List<ClassVo> list = submittedClassMapper.selectClassVoList(classVo);
		 Boolean flag = false;
		if(list!=null&&list.size()>0){
			flag = true;
		}
		 return flag;
	}

	@Override
	public void updateBatch(List<ClassVo> classVoList) {
		submittedClassMapper.updateBatch(classVoList);
	}

	@Override
	public PageVO<ClassVo> page(PageDTO pageDTO, ClassVo classVo) {
		return PageUtil.doPage(pageDTO, () -> submittedClassMapper.selectClassVoList(classVo));
	}
}
